setwd("/Users/ericguntermann/Documents/Papers/Representation of Party Preferences/Replication")
# This file produces figure 1
library(foreign)
load("cses.Rda")
cses <- cses1_4
cses <- cses[-which(cses$countryyear %in% c("Japan 2013")),]
## Only keep parliamentary and semi-presidential regimes
cses <- cses[!is.na(cses$regime), ]
cses <- cses[cses$regime<2,]
cses <- cses[order(cses$countryyear),]

ld <- cses[,grep("likedislike",colnames(cses))]


ld[is.na(ld)] <- 11
rowtot <- rowSums(ld, na.rm=T)
ld <- ld[!rowtot==99,]
ld[ld==11] <-NA


noratings <- vector()

for(i in 1:nrow(ld)){
  noratings[i] <- length(unique(na.omit(as.numeric(ld[i,]))))
}

nrdf <- data.frame(cy=cses$countryyear[!rowtot==99], noratings=noratings)

library(ggplot2)

pdf("noofratings.pdf")
ggplot(nrdf, aes(x=as.factor(noratings))) + geom_bar(aes(y = (..count..)/sum(..count..))) + xlab("Number of Ratings") + ylab("Proportion") + theme_bw()
dev.off()